package com.hejielife.delayed;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 2019年8月1日 下午3:53:59
 * 
 * @author hejielife
 * @despribe 网民实现Delayed借口
 */
public class Wangmin implements Delayed {

	private String name;
	// 身份证
	private String id;
	// 截止时间
	private long endTime;
	// 定义时间工具类
	private TimeUnit timeUnit = TimeUnit.SECONDS;

	public Wangmin(String name, String id, long endTime) {
		this.name = name;
		this.id = id;
		this.endTime = endTime;
	}

	public String getName() {
		return this.name;
	}

	public String getId() {
		return this.id;
	}

	/**
	 * 用来判断是否到了截止时间
	 */
	public long getDelay(TimeUnit unit) {
		// return unit.convert(endTime, TimeUnit.MILLISECONDS) -
		// unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
		return endTime - System.currentTimeMillis();
	}

	/**
	 * 相互批较排序用
	 */
	public int compareTo(Delayed delayed) {
		Wangmin w = (Wangmin) delayed;
		return this.getDelay(this.timeUnit) - w.getDelay(this.timeUnit) > 0 ? 1 : 0;
	}

}